package com.lxh.lxhcrm.model.service;

import com.lxh.lxhcrm.model.dao.productManagement.AppCaiDao;
import com.lxh.lxhcrm.model.dao.productManagement.AppDetailDao;
import com.lxh.lxhcrm.model.dao.productManagement.CaigouDao;
import com.lxh.lxhcrm.model.dao.productManagement.SupplierDao;
import com.lxh.lxhcrm.model.mappers.emp.EmpMapper;
import com.lxh.lxhcrm.model.mappers.productManagement.CaigouMapper;
import com.lxh.lxhcrm.model.pojos.*;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Date;
import java.util.List;

@Service
public class CaigouService {
    @Resource
    CaigouMapper caigouMapper;
    /*
     * 查询
     * */
    //申请采购表列表查询
    public List<AppCai> findAppCai(String searchText, Integer selectModel,Integer judge){return caigouMapper.findAppCai(searchText,selectModel,judge);}
    //无分页查询申请采购表
    public List<AppCai> allAppCai(){return caigouMapper.allAppCai();}
    //采购表列表查询
    public List<Caigou> findCaigou(String searchText, Integer selectModel,Integer judge){return caigouMapper.findCaigou(searchText,selectModel,judge);}
    //无分页查询采购表
    public List<Caigou> allCaigou(){return caigouMapper.allCaigou();}
    //供货商查询
    public List<Supplier> findSupplier(){return caigouMapper.findSupplier();}
    //支付方式查询
    public List<PayWey> findPayWey(){return caigouMapper.findPayWey();}
    //交货方式查询
    public List<DeliveryType> findDeliveryType(){return caigouMapper.findDeliveryType();}
    //发票类别查询
    public List<InvoiceType> findInvoiceType(){return caigouMapper.findInvoiceType();}
    //付款约定查询
    public List<AppointPay> findAppointPay(){return caigouMapper.findAppointPay();}
    @Resource
    EmpMapper empMapper;
    //查询此用户是否具备审核功能
    public boolean findDuty(Integer empId){
        boolean index = false;
        int item = empMapper.findDuty(empId);
        if(item == 1 || item == 10){
            index = true;
        }
        return index;
    }
    /*
     * 新增
     * */
    @Resource
    SupplierDao supplierDao;
    //添加供货商
    public void addSupplier(Supplier supplier){
        supplierDao.save(supplier);
    }
    @Resource
    AppCaiDao appCaiDao;
    @Resource
    AppDetailDao appDetailDao;
    //添加申请采购抬头表
    public void addAppCai(AppCai appCai) {
        appCaiDao.save(appCai);
        for (AppDetail appDetail: appCai.getAppDetail()) {
            appDetail.setAppCai(appCai);
            addAppDetail(appDetail);
        }
    }
    //添加申请采购详情表
    public void addAppDetail(AppDetail appDetail) { appDetailDao.save(appDetail);}
    @Resource
    CaigouDao caigouDao;
    //添加采购表
    public void addCaigou(Caigou caigou){ caigouDao.save(caigou);}
    /*
     * 修改
     * */
    //修改申请采购表状态
    public void changeAppCaiState(Integer judge,Integer appCaiId){caigouMapper.changeAppCaiState(judge,appCaiId);}
    //修改采购表状态
    public void changeCaiState(Integer judge,Integer caiId){caigouMapper.changeCaiState(judge,caiId);}
    //修改采购表
    public void updateCai(Integer empId, Integer deliveryId, Integer invoiceId, Integer payId, Integer appointId, Date deliveryDate, String caddDel, Integer caiId){
        caigouMapper.updateCai(empId,deliveryId,invoiceId,payId,appointId,deliveryDate,caddDel,caiId);
    }
}
